package caculate;

import java.io.*;
import java.util.*;

import analysis.GetUserPopularity;
import utils.*;
import io.*;
public class RankUser {
	List<UserForTest> allUsers;
	Map<Integer,Double> userScoreData;
	//HashSet<Integer> 
	void loadTestData() throws IOException	{
		LoadTestData dataLoader = new LoadTestData();
		dataLoader.loadData(dataLoader.testFile);
		allUsers = dataLoader.allUsers;
	}
	void caculateScoreAndRank()	{
		try {
			GetUserPopularity.LoadPopularityScore();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		userScoreData = GetUserPopularity.userScore;
		for(UserForTest user:allUsers){
			for(UserRecCount userB:user.allUserB){
				if(userScoreData.containsKey(userB.id))
					userB.score = userScoreData.get(userB.id);
				else 	{
					userB.score = 0;
					System.out.println(userB.id);
				}
					
			}
			user.rankUserB();
		}
		
		
	}
	void outputResult(String fileName) throws IOException	{
		BufferedWriter bWriter = new BufferedWriter(new FileWriter(fileName));
		for(UserForTest user:allUsers)	{
			bWriter.write(user.toString());bWriter.newLine();
		}
		bWriter.close();
	}
	public static void main(String[] args) throws IOException	{
		
		RankUser ru = new RankUser();
		ru.loadTestData();
		ru.caculateScoreAndRank();
		ru.outputResult("rank1.txt");
	}
	
}
